﻿using System;
using System.Collections.Generic;
using wojilu.ORM;
using wojilu.Web.Mvc;

namespace wojilu.Apps.Qycms.Domain
{
    [Table("ybb_typelist")]
    [Serializable]
    public class TypeList : ObjectBase<TypeList>
    {
        [NotNull(""), Default(50), Column(Length = 5)]
        public Int32 pid { get; set; }

        [NotNull(""), Default(0), Column(Length = 5)]
        public Int32 mid { get; set; }

        [NotNull(""), Default(0), Column(Length = 5)]
        public Int32 topid { get; set; }

        [NotNull(""), Default(0), Column(Length = 5)]
        public Int32 upid { get; set; }

        [NotNull(""), Default(0), Column(Length = 5)]
        public Int32 exmid { get; set; }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int32 linkid { get; set; }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int32 gotoid { get; set; }

        [NotNull(""), Default("cn"), Column(Length = 50)]
        public String lng { get; set; }

        [NotNull(""), Column(Length = 150)]
        public String typename { get; set; }

        [Column(Length = 150)]
        public String othertypename { get; set; }

        [LongText]
        public String content { get; set; }

        [LongText]
        public String indexcontent { get; set; }

        [Column(Length = 200)]
        public String headtitle { get; set; }

        [Default(""), Column(Length = 80)]
        public String keywords { get; set; }

        [Column(Length = 180)]
        public String description { get; set; }

        [Column(Length = 200)]
        public String typepic { get; set; }

        [Column(Length = 200)]
        public String indextypepic { get; set; }

        [NotNull(""), Default(""), Column(Length = 50)]
        public String dirname { get; set; }

        [TinyInt, NotNull(""), Default(0), Column(Length = 1)]
        public Int32 purview { get; set; }

        [TinyInt, NotNull(""), Default(0), Column(Length = 1)]
        public Int32 ismenu { get; set; }

        [TinyInt, NotNull(""), Default(0), Column(Length = 1)]
        public Int32 isaccessory { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 isclass { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 ispart { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 styleid { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 pageclass { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String indextemplates { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String template { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String readtemplate { get; set; }

        [NotNull(""), Default(""), Column(Length = 100)]
        public String filenamestyle { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String readnamestyle { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 isline { get; set; }

        [NotNull(""), Default(0), Column(Length = 11)]
        public Int32 gotoline { get; set; }

        [NotNull(""), Column(Length = 200)]
        public String typeurl { get; set; }

        [Column(Length = 150)]
        public String dirpath { get; set; }

        [TinyInt, NotNull(""), Default(0), Column(Length = 1)]
        public Int32 iswap { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String waptempalte { get; set; }

        [NotNull(""), Column(Length = 100)]
        public String wapreadtemplate { get; set; }

        [NotNull(""), Default(0), Column(Length = 5)]
        public Int32 pagemax { get; set; }

        [NotNull("")]
        public DateTime addtime { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 isorderby { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 ordertype { get; set; }

        [TinyInt, NotNull(""), Default(1), Column(Length = 1)]
        public Int32 isshow { get; set; }

        [NotSave]
        public String ModelName
        {
            get
            {
                Model m = Model.findById(mid);
                return m.modelname;
            }
        }

        [NotSave]
        public List<TypeList> Child
        {
            get
            {
                var list = TypeList.find(" upid =:u and isclass = 1 and isshow = 1 order by pid asc,id asc").set("u", Id).list();
                return list;
            }
        }

        [NotSave]
        public List<TypeList> MChild
        {
            get
            {
                var list = TypeList.find(" upid =:u and isclass = 1 and mid=:m order by pid asc,id asc").set("u", Id).set("m", mid).list();
                return list;
            }
        }

        [NotSave]
        public Int32 level 
        {
            get
            {
                if (topid == 0) return 0;
                TypeList t = TypeList.findById(upid);
                return t.level + 1;
            }
        }

        [NotSave]
        public Int32 level1
        {
            get
            {
                if (topid == 0) return 0;
                TypeList t = TypeList.findById(upid);
                if (t.mid != mid)
                {
                    return 0;
                }
                return t.level + 1;
            }
        }

        [NotSave]
        public String stylename
        {
            get
            {
                switch (styleid)
                {
                    case 1:
                        return "<font color=\"#489D66\">" + lang.get("typemanage_text_styleid1") + "<font>";

                    case 2:
                        return lang.get("typemanage_text_styleid2");

                    case 3:
                        return "<font color=\"#FF0F0F\">" + lang.get("typemanage_text_styleid3") + "<font>";

                    case 4:
                        return "<font color=\"#2E43E0\">" + lang.get("typemanage_text_styleid4") + "<font>";
                }
                return string.Empty;
            }
        }

        [NotSave]
        public String glink
        {
            get
            {
                if (styleid == 3)
                {
                    if (isline == 1)
                    {
                        return typeurl;
                    }
                    else
                    {
                        return strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Article"), "List"), Id.ToString()) + MvcConfig.Instance.UrlExt;
                    }
                }
                else
                {
                    return strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Article"), "List"), Id.ToString()) + MvcConfig.Instance.UrlExt;
                }
            }
        }

        [NotSave]
        public String gwaplink
        {
            get
            {
                if (styleid == 3)
                {
                    if (isline == 1)
                    {
                        return typeurl;
                    }
                    else
                    {
                        return strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Wap/Article"), "List"), Id.ToString()) + MvcConfig.Instance.UrlExt;
                    }
                }
                else
                {
                    return strUtil.Join(strUtil.Join(strUtil.Join(sys.Path.Root, "Wap/Article"), "List"), Id.ToString()) + MvcConfig.Instance.UrlExt;
                }
            }
        }

    }
}
